package it.gma.torero.parsing;

import it.gma.torero.operand.BooleanOperand;
import it.gma.torero.parsing.Tokenizer.MalformedException;
import it.gma.torero.parsing.token.Token;

import java.util.HashMap;
import java.util.Map;

public class Parser {

	private static Map<String, Token> cache = new HashMap<String, Token>();
	
	public static BooleanOperand parse(String toParse) throws MalformedException {
		Token token = null;
		if (cache.get(toParse) == null) {
			cache.put(toParse, ExpressionTreeBuilder.getRoot(new Tokenizer(toParse)));
		}
		
		
		token = cache.get(toParse);		
		
		return (BooleanOperand) token.asOperand();
	}

}
